<template>
  <div class="wrapper">
    <swiper :options="swiperOption"
            v-if="showSwiper">
      <swiper-slide v-for="item of swiperList"
                    :key="item.id">
        <img class="swiper-img"
             :src="item.imgUrl"
             alt="图片">
      </swiper-slide>
      <div class="swiper-pagination"
           slot="pagination"></div>
    </swiper>
  </div>

</template>

<script>
export default {
  name: 'HomeSwiper',
  props: {
    swiperList: Array
  },
  // es5 写法
  // data: function () {

  // }
  // es6 写法
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination', // 小圆点
        loop: true
      }
    }
  },
  computed: {
    showSwiper () {
      return this.swiperList.length
    }
  }
}
</script>

<style lang="stylus" scoped>
// 由于scoped，直接修改样式不起作用，需要下面的样式穿透
.wrapper >>> .swiper-pagination-bullet-active {
  background-color: #fff;
}

// 防止加载慢时，图片后出现，导致图片下方的内容抖动
.wrapper {
  overflow: hidden;
  // height: 30.48%vw;
  width: 100%;
  height: 0;
  padding-bottom: 30.48%; // 轮播图的高宽比例

  .swiper-img {
    width: 100%;
  }
}
</style>
